<!--
描述：系统应用-菜单管理-菜单添加、编辑
开发人：hqj
开发日期：2018年05月25日
-->
<template lang="pug">
    el-dialog(bizKey="adminPaper" class="theme1" ref="kalixBizDialog" title="自动组卷" v-bind:visible.sync="visible"
    v-bind:append-to-body="true" v-bind:close-on-click-modal="false" v-bind:before-close="close")
        div(style="height:100%;")
            keep-alive
                kalix-table(bizKey="adminMenu" title='参数列表' v-bind:targetURL="targetURL"
                 v-bind:isFixedColumn="isFixedColumn" v-bind:toolbarBtnList="ruleToolbarBtnList" v-bind:customToolBar="paperCustomToolBar"
                v-bind:dictDefine="dictDefine" ref="ruleTable" )
                    template(slot="tableColumnSlot")
                        el-table-column(prop="titleNumName" label="试题顺序" align="center" )
                        el-table-column(prop="quesTypeName" label="试题题型" align="center" )
                        el-table-column(prop="quesScore" label="每题分数" align="center" )
                        el-table-column(prop="quesTotalscore" label="试题总分" align="center" )
                        el-table-column(prop="quesDesc" label="题型描述" align="center" )
</template>

<script type="text/ecmascript-6">
    import PaperFormModel from './paperModel'
    import RuleFormModel from './ruleModel'
    import {AutoPaperURL,PaperDataURL} from '../config.toml'
    export default {
        name:'DoPaperView',
        data() {
            return {
                dictDefine: [{
                    cacheKey: 'ENROLMENT-DICT-KEY',
                    type: '题型顺序',
                    targetField: 'titleNumName',
                    sourceField: 'titleNum'
                },{
                    cacheKey: 'ENROLMENT-DICT-KEY',
                    type: '题型',
                    targetField: 'quesTypeName',
                    sourceField: 'quesType'
                }],
                ruleToolbarBtnList: [
                    {id: 'add', isShow: false},
                    {id: 'doSave', title: '提交', isShow: true, icon: 'icon-add'}
                ],
                jsonStr: '{"delFlag": "0"}',
                visible: false,
                formModel:  Object.assign({}, PaperFormModel),
                targetURL: '' ,
                labelWidth: '110px',
                // 试卷规则和试题规则列表
                isFixedColumn: true
            }
        },
        components: {
        },
        watch: {
//      formModel: {
//        handler: 'watchFormModel',
//        deep: true
//      }
        },
        methods: {
            // 试卷规则列表自定义工具栏
            paperCustomToolBar(btnId, table) {
                switch (btnId) {
                    case 'doSave': {
                        this.onPaperNewAdd(table)
                        break
                    }
                }
            },
            // 添加试卷规则
            onPaperNewAdd(table) {
                const loading = this.$loading({
                    lock: true,
                    text: '自动组卷进行中，请稍等...',
                    spinner: 'el-icon-loading',
                    background: 'rgba(255, 255, 255, 0.7)'
                })
                this.axios.request({
                    method: 'get',
                    url: PaperDataURL,
                    params: {
                        id: this.formModel.id
                    }
                }).then(response => {
                    if (response.data) {
                       // this.download(response.data)
                        this.$KalixMessage.success(response.data.msg)
                    } else {
                        this.$KalixMessage.error('生成试卷失败！')
                    }
                    loading.close()
                }).catch((e) => {
                    this.$KalixMessage.error('生成试卷！原因：' + e.message)
                    loading.close()
                })
            },
            open(_title, isEdit = false,model, row) {
                this.title = _title
                this.visible = true
                this.isEdit = isEdit
                if (row) {
                    this.formModel = row
                    this.targetURL=row.targetURL
                } else {
                    this.formModel = Object.assign({}, model)
                }
            },
            close() {
                this.doClearForm()
                this.doCloseDialog()
            },
            doClearForm() {
              //  this.$refs.dialogForm.resetFields()
                this.formModel = Object.assign({}, RuleFormModel)
                this.active = 1
            },
            doCloseDialog() {
                this.visible = false
                this.$KalixEventBus.$emit('adminPaper' + '-' + 'KalixDialogClose', null)
            }

        }
    }
</script>

<style  lang='stylus' type='text/stylus'>
    .theme1
        .el-dialog__body
            height 400px


</style>
